/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \brief for testing pos.cxx
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2023-10-18
  \date 2023-10-18 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2023-10-18   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "ETFMath.h"

static const double deg = ETFMath::DEGREE();

using std::string;
using std::cout;
using std::endl;
using std::ofstream;

void pos(const double *p, const double *ang, bool isDC1, ofstream &f);

int main(){
  ofstream f("pos.txt");
  const double p0[3] = {740., 15.9786, 1956.}, a0[3] = {15., 0., 0.}; // DC0
  const double p1[3] = {937.82, 9.47433, 3500.}, a1[3] = {15., 0., 0.}; // DC1
  const double p2[3] = {1339.75, 9.90031, 5000.}, a2[3] = {15., 0., 0.}; // DC2
  const double pt[3] = {2210.58, 0.0, 8250.}, at[3] = {15., 0., 0.}; // TOFWall

  pos(p0, a0, false, f);  
  pos(p1, a1, true, f);
  pos(p2, a2, false, f);

  cout << endl << "------------------- TOFW ----------------" << endl;
  const double LH = 1360./2.;
  cout << "xl: " << pt[0]-LH*cos(at[0]*deg) << ", zl: " << pt[2]+LH*sin(at[0]*deg) << endl;
  cout << "xr: " << pt[0]+LH*cos(at[0]*deg) << ", zr: " << pt[2]-LH*sin(at[0]*deg) << endl;
  f << endl << "------------------- TOFW ----------------" << endl;
  f << "xl: " << pt[0]-LH*cos(at[0]*deg) << ", zl: " << pt[2]+LH*sin(at[0]*deg) << endl;
  f << "xr: " << pt[0]+LH*cos(at[0]*deg) << ", zr: " << pt[2]-LH*sin(at[0]*deg) << endl;

  f.close();
  return 0;
} // end main function

void pos(const double *p, const double *ang, bool isDC1, ofstream &f){
  double a[3]{}, b[3]{}, c[3]{}, d[3]{};
  ETFMath::InvPos(a, b, c, d, p, ang, isDC1);

  cout << std::fixed << std::setprecision(2);
  cout << endl << "-----------------------" << endl;
  cout << "    a: [" << a[0] << ", " << a[1] << ", " << a[2] << "]" << endl;
  cout << "    b: [" << b[0] << ", " << b[1] << ", " << b[2] << "]" << endl;
  cout << "    c: [" << c[0] << ", " << c[1] << ", " << c[2] << "]" << endl;
  cout << "    d: [" << d[0] << ", " << d[1] << ", " << d[2] << "]" << endl;

  f << std::fixed << std::setprecision(2);
  f << endl << "-----------------------" << endl;
  f << "a: [" << a[0] << ", " << a[1] << ", " << a[2] << "]" << endl;
  f << "b: [" << b[0] << ", " << b[1] << ", " << b[2] << "]" << endl;
  f << "c: [" << c[0] << ", " << c[1] << ", " << c[2] << "]" << endl;
  f << "d: [" << d[0] << ", " << d[1] << ", " << d[2] << "]" << endl;
} // end function pos